

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=dark>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/icon/dw.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Memory">
  <meta name="keywords" content="">
  
    <meta name="description" content="🥣 突破瓶颈，实现从理论到实践的完美过渡，掌握消息队列的核心技巧">
<meta property="og:type" content="article">
<meta property="og:title" content="驾驭风暴：RabbitMQ实战之旅——揭秘消息队列的无限潜能">
<meta property="og:url" content="http://example.com/2023/10/25/%E9%A9%BE%E9%A9%AD%E9%A3%8E%E6%9A%B4%EF%BC%9ARabbitMQ%E5%AE%9E%E6%88%98%E4%B9%8B%E6%97%85%E2%80%94%E2%80%94%E6%8F%AD%E7%A7%98%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97%E7%9A%84%E6%97%A0%E9%99%90%E6%BD%9C%E8%83%BD/index.html">
<meta property="og:site_name" content="Memory&#39;s blog">
<meta property="og:description" content="🥣 突破瓶颈，实现从理论到实践的完美过渡，掌握消息队列的核心技巧">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/img/artical/girl15.jpg">
<meta property="article:published_time" content="2023-10-25T14:05:34.000Z">
<meta property="article:modified_time" content="2024-01-15T08:10:08.000Z">
<meta property="article:author" content="Memory">
<meta property="article:tag" content="经验">
<meta property="article:tag" content="RabbitMQ">
<meta property="article:tag" content="消息队列">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="http://example.com/img/artical/girl15.jpg">
  
  
  
  <title>驾驭风暴：RabbitMQ实战之旅——揭秘消息队列的无限潜能 - Memory&#39;s blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.4","typing":{"enable":true,"typeSpeed":100,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":false,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  

  

  

  

  

  

  

  



  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 75vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Memory&#39;s blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/newBG/girl.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="驾驭风暴：RabbitMQ实战之旅——揭秘消息队列的无限潜能"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        Memory
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-10-25 22:05" pubdate>
          2023年10月25日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          7.4k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          19 分钟
        
      </span>
    

    
    
      
        <span id="leancloud-page-views-container" class="post-meta" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="leancloud-page-views"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar category-bar" style="margin-right: -1rem">
    





<div class="category-list">
  
  
    
    
    
    <div class="category row nomargin-x">
      <a class="category-item 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="消息队列"
        id="heading-8bedb7aae7ae74964d0363a1556c7a59" role="tab" data-toggle="collapse" href="#collapse-8bedb7aae7ae74964d0363a1556c7a59"
        aria-expanded="true"
      >
        消息队列
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-8bedb7aae7ae74964d0363a1556c7a59"
           role="tabpanel" aria-labelledby="heading-8bedb7aae7ae74964d0363a1556c7a59">
        
        
          
          
  <div class="category-post-list">
    
    
  </div>

          
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="RabbitMQ"
        id="heading-7eaa993723e57b3bfc99923c196e2e17" role="tab" data-toggle="collapse" href="#collapse-7eaa993723e57b3bfc99923c196e2e17"
        aria-expanded="true"
      >
        RabbitMQ
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-7eaa993723e57b3bfc99923c196e2e17"
           role="tabpanel" aria-labelledby="heading-7eaa993723e57b3bfc99923c196e2e17">
        
        
          
          
  <div class="category-post-list">
    
    
  </div>

          
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="经验"
        id="heading-32a8e000e928e6dc255876d9fc0178b3" role="tab" data-toggle="collapse" href="#collapse-32a8e000e928e6dc255876d9fc0178b3"
        aria-expanded="true"
      >
        经验
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-32a8e000e928e6dc255876d9fc0178b3"
           role="tabpanel" aria-labelledby="heading-32a8e000e928e6dc255876d9fc0178b3">
        
        
          
  <div class="category-post-list">
    
    
      
      
        <a href="/2023/10/25/%E9%A9%BE%E9%A9%AD%E9%A3%8E%E6%9A%B4%EF%BC%9ARabbitMQ%E5%AE%9E%E6%88%98%E4%B9%8B%E6%97%85%E2%80%94%E2%80%94%E6%8F%AD%E7%A7%98%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97%E7%9A%84%E6%97%A0%E9%99%90%E6%BD%9C%E8%83%BD/" title="驾驭风暴：RabbitMQ实战之旅——揭秘消息队列的无限潜能"
           class="list-group-item list-group-item-action
           active">
          <span class="category-post">驾驭风暴：RabbitMQ实战之旅——揭秘消息队列的无限潜能</span>
        </a>
      
    
  </div>

        
      </div>
    </div>
  
        
      </div>
    </div>
  
        
      </div>
    </div>
  
</div>


  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">驾驭风暴：RabbitMQ实战之旅——揭秘消息队列的无限潜能</h1>
            
              <p class="note note-success">
                
                  
                    本文最后更新于：6 个月前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="破冰"><a href="#破冰" class="headerlink" title="破冰"></a>破冰</h1><ul>
<li>🔥 推荐阅读：</li>
</ul>
<blockquote>
<h5 id="消息队列基础知识总结-JavaGuide-Java面试-学习指南"><a href="#消息队列基础知识总结-JavaGuide-Java面试-学习指南" class="headerlink" title="消息队列基础知识总结 | JavaGuide(Java面试 + 学习指南)"></a><a target="_blank" rel="noopener" href="https://javaguide.cn/high-performance/message-queue/message-queue.html">消息队列基础知识总结 | JavaGuide(Java面试 + 学习指南)</a></h5><h5 id="java消息队列基础和RabbitMQ相关概念-掘金-juejin-cn"><a href="#java消息队列基础和RabbitMQ相关概念-掘金-juejin-cn" class="headerlink" title="java消息队列基础和RabbitMQ相关概念 - 掘金 (juejin.cn)"></a><a target="_blank" rel="noopener" href="https://juejin.cn/post/7268590610189189157">java消息队列基础和RabbitMQ相关概念 - 掘金 (juejin.cn)</a></h5><h5 id="Windows10上RabbitMQ安装和启动详细步骤-行业资讯-电子产品设计开发与电子技术学习交流！-52dianzi-com"><a href="#Windows10上RabbitMQ安装和启动详细步骤-行业资讯-电子产品设计开发与电子技术学习交流！-52dianzi-com" class="headerlink" title="Windows10上RabbitMQ安装和启动详细步骤 - 行业资讯 - 电子产品设计开发与电子技术学习交流！ (52dianzi.com)"></a><a target="_blank" rel="noopener" href="https://www.52dianzi.com/category/article/d7f36b95eb8155ed15222b17a5b46b40.html">Windows10上RabbitMQ安装和启动详细步骤 - 行业资讯 - 电子产品设计开发与电子技术学习交流！ (52dianzi.com)</a></h5></blockquote>
<h1 id="思维碰撞"><a href="#思维碰撞" class="headerlink" title="思维碰撞"></a>思维碰撞</h1><h2 id="基础知识介绍"><a href="#基础知识介绍" class="headerlink" title="基础知识介绍"></a>基础知识介绍</h2><h2 id="小试牛刀（实操）"><a href="#小试牛刀（实操）" class="headerlink" title="小试牛刀（实操）"></a>小试牛刀（实操）</h2><h3 id="RabbitMQ"><a href="#RabbitMQ" class="headerlink" title="RabbitMQ"></a>RabbitMQ</h3><h4 id="下载安装"><a href="#下载安装" class="headerlink" title="下载安装"></a>下载安装</h4><blockquote>
<h5 id="🍝-RabbitMQ-官网：Documentation-Table-of-Contents-—-RabbitMQ"><a href="#🍝-RabbitMQ-官网：Documentation-Table-of-Contents-—-RabbitMQ" class="headerlink" title="🍝 RabbitMQ 官网：Documentation: Table of Contents — RabbitMQ"></a>🍝 RabbitMQ 官网：<a target="_blank" rel="noopener" href="https://www.rabbitmq.com/documentation.html">Documentation: Table of Contents — RabbitMQ</a></h5></blockquote>
<ul>
<li><h5 id="参考阅读："><a href="#参考阅读：" class="headerlink" title="参考阅读："></a>参考阅读：</h5></li>
<li><h5 id="Windows10上RabbitMQ安装和启动详细步骤-行业资讯-电子产品设计开发与电子技术学习交流！-52dianzi-com-1"><a href="#Windows10上RabbitMQ安装和启动详细步骤-行业资讯-电子产品设计开发与电子技术学习交流！-52dianzi-com-1" class="headerlink" title="Windows10上RabbitMQ安装和启动详细步骤 - 行业资讯 - 电子产品设计开发与电子技术学习交流！ (52dianzi.com)"></a><a target="_blank" rel="noopener" href="https://www.52dianzi.com/category/article/d7f36b95eb8155ed15222b17a5b46b40.html">Windows10上RabbitMQ安装和启动详细步骤 - 行业资讯 - 电子产品设计开发与电子技术学习交流！ (52dianzi.com)</a></h5></li>
</ul>
<blockquote>
<p>🍜 <strong>RabbitMQ 下载</strong>（如下图所示）：</p>
<ul>
<li><h5 id="下载地址：Downloads-Erlang-OTP"><a href="#下载地址：Downloads-Erlang-OTP" class="headerlink" title="下载地址：Downloads - Erlang/OTP"></a>下载地址：<a target="_blank" rel="noopener" href="https://www.erlang.org/downloads">Downloads - Erlang/OTP</a></h5></li>
<li><p>因为 RabbitMQ 服务端是使用并发式语言 Erlang 编写的，安装 Rabbit MQ 的前提是安装 Erlang</p>
</li>
</ul>
</blockquote>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20231025224213573.png" alt="image-20231025224213573"></p>
<blockquote>
<p>🍖 <strong>Erlang 下载</strong>（如下图所示）：</p>
<ul>
<li><h5 id="下载地址：Installing-on-Windows-—-RabbitMQ"><a href="#下载地址：Installing-on-Windows-—-RabbitMQ" class="headerlink" title="下载地址：Installing on Windows — RabbitMQ"></a>下载地址：<a target="_blank" rel="noopener" href="https://www.rabbitmq.com/install-windows.html">Installing on Windows — RabbitMQ</a></h5></li>
</ul>
</blockquote>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20231025224007271.png" alt="image-20231025224007271"></p>
<h4 id="安装监控面板"><a href="#安装监控面板" class="headerlink" title="安装监控面板"></a>安装监控面板</h4><ul>
<li>在 <strong>sbin 目录下</strong>执行以下命令，安装 <strong>rabbitmq 监控面板</strong>：<strong>（2023/10/25晚）</strong></li>
</ul>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs routeros">rabbitmq-plugins <span class="hljs-built_in">enable</span> rabbitmq_management<br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20231025224956930.png" alt="image-20231025224956930"></p>
<h4 id="启动"><a href="#启动" class="headerlink" title="启动"></a>启动</h4><ul>
<li>在 <strong>sbin 目录下</strong>执行以下命令，<strong>启动 rabbitmq</strong>：</li>
</ul>
<figure class="highlight axapta"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs axapta">rabbitmq-<span class="hljs-keyword">server</span>.bat<br></code></pre></td></tr></table></figure>

<ul>
<li>可以在<strong>任务管理器</strong>处检查 <strong>RabbitMQ 服务是否正常启动</strong>：</li>
</ul>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20231025220542254.png" alt="image-20231025220542254"></p>
<h4 id="登入监控面板"><a href="#登入监控面板" class="headerlink" title="登入监控面板"></a>登入监控面板</h4><ul>
<li>访问 <code>http://localhost:15672</code>，输入初始账号密码，<strong>登入监控面板</strong>：</li>
</ul>
<blockquote>
<h5 id="默认账号：guest"><a href="#默认账号：guest" class="headerlink" title="默认账号：guest"></a>默认账号：guest</h5><h5 id="默认密码：guest"><a href="#默认密码：guest" class="headerlink" title="默认密码：guest"></a>默认密码：guest</h5></blockquote>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20231025225355025.png" alt="image-20231025225355025"></p>
<h2 id="SpringBoot-集成-RabbitMQ"><a href="#SpringBoot-集成-RabbitMQ" class="headerlink" title="SpringBoot 集成 RabbitMQ"></a>SpringBoot 集成 RabbitMQ</h2><h3 id="简单的-demo-演示"><a href="#简单的-demo-演示" class="headerlink" title="简单的 demo 演示"></a>简单的 demo 演示</h3><h4 id="导入依赖"><a href="#导入依赖" class="headerlink" title="导入依赖"></a>导入依赖</h4><blockquote>
<p>🥣 RabbitMQ 的相关依赖坐标可以在 mvn 中找到，依赖坐标可以在官方文档中查到：</p>
</blockquote>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20231026130836071.png" alt="image-20231026130836071"></p>
<hr>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20231026131014940.png" alt="image-20231026131014940"></p>
<ul>
<li>在 <strong>MVN 仓库</strong>中查找到依赖并导入：</li>
</ul>
<blockquote>
<h5 id="🍖-Maven-Repository-com-rabbitmq-»-amqp-client-»-5-19-0-mvnrepository-com"><a href="#🍖-Maven-Repository-com-rabbitmq-»-amqp-client-»-5-19-0-mvnrepository-com" class="headerlink" title="🍖 Maven Repository: com.rabbitmq » amqp-client » 5.19.0 (mvnrepository.com)"></a>🍖 <a target="_blank" rel="noopener" href="https://mvnrepository.com/artifact/com.rabbitmq/amqp-client/5.19.0">Maven Repository: com.rabbitmq » amqp-client » 5.19.0 (mvnrepository.com)</a></h5></blockquote>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-comment">&lt;!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client --&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.rabbitmq<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>amqp-client<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.19.0<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>     <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h4 id="简单的-Producer-Receiver"><a href="#简单的-Producer-Receiver" class="headerlink" title="简单的 Producer / Receiver"></a>简单的 Producer / Receiver</h4><blockquote>
<p>🍟 定义简单的生产者和消费者，完成 demo 代码的编写。当然，这部分代码也可以在<strong>官方文档</strong>中找到</p>
<p>🍛 </p>
</blockquote>
<h4 id="生产消息-demo"><a href="#生产消息-demo" class="headerlink" title="生产消息 demo"></a>生产消息 demo</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 消息生产者</span><br><span class="hljs-comment"> */</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">MessageProducer</span> &#123;<br><br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-type">String</span> <span class="hljs-variable">QUEUE_NAME</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;hello3&quot;</span>;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] argv)</span> <span class="hljs-keyword">throws</span> Exception &#123;<br>        <span class="hljs-type">ConnectionFactory</span> <span class="hljs-variable">factory</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">ConnectionFactory</span>();<br>        factory.setHost(<span class="hljs-string">&quot;localhost&quot;</span>);<br>        <span class="hljs-keyword">try</span> (<span class="hljs-type">Connection</span> <span class="hljs-variable">connection</span> <span class="hljs-operator">=</span> factory.newConnection();<br>             <span class="hljs-type">Channel</span> <span class="hljs-variable">channel</span> <span class="hljs-operator">=</span> connection.createChannel()) &#123;<br>            channel.queueDeclare(QUEUE_NAME, <span class="hljs-literal">false</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">null</span>);<br>            <span class="hljs-type">String</span> <span class="hljs-variable">message</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;Hello World!&quot;</span>;<br>            channel.basicPublish(<span class="hljs-string">&quot;&quot;</span>, QUEUE_NAME, <span class="hljs-literal">null</span>, message.getBytes(StandardCharsets.UTF_8));<br>            System.out.println(<span class="hljs-string">&quot; [x] Sent &#x27;&quot;</span> + message + <span class="hljs-string">&quot;&#x27;&quot;</span>);<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="消费消息-demo"><a href="#消费消息-demo" class="headerlink" title="消费消息 demo"></a>消费消息 demo</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 消息消费者</span><br><span class="hljs-comment"> */</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">MessageReceiver</span> &#123;<br><br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-type">String</span> <span class="hljs-variable">QUEUE_NAME</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;hello3&quot;</span>;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] argv)</span> <span class="hljs-keyword">throws</span> Exception &#123;<br>        <span class="hljs-type">ConnectionFactory</span> <span class="hljs-variable">factory</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">ConnectionFactory</span>();<br>        factory.setHost(<span class="hljs-string">&quot;localhost&quot;</span>);<br>        <span class="hljs-type">Connection</span> <span class="hljs-variable">connection</span> <span class="hljs-operator">=</span> factory.newConnection();<br>        <span class="hljs-type">Channel</span> <span class="hljs-variable">channel</span> <span class="hljs-operator">=</span> connection.createChannel();<br><br>        channel.queueDeclare(QUEUE_NAME, <span class="hljs-literal">false</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">null</span>);<br>        System.out.println(<span class="hljs-string">&quot; [*] Waiting for messages. To exit press CTRL+C&quot;</span>);<br><br>        <span class="hljs-type">DeliverCallback</span> <span class="hljs-variable">deliverCallback</span> <span class="hljs-operator">=</span> (consumerTag, delivery) -&gt; &#123;<br>            <span class="hljs-type">String</span> <span class="hljs-variable">message</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">String</span>(delivery.getBody(), StandardCharsets.UTF_8);<br>            System.out.println(<span class="hljs-string">&quot; [x] Received &#x27;&quot;</span> + message + <span class="hljs-string">&quot;&#x27;&quot;</span>);<br>        &#125;;<br>        channel.basicConsume(QUEUE_NAME, <span class="hljs-literal">true</span>, deliverCallback, consumerTag -&gt; &#123;<br>        &#125;);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="效果展示"><a href="#效果展示" class="headerlink" title="效果展示"></a>效果展示</h4><blockquote>
<p>🍿 启动 <strong>MessageProducer</strong> 分别生产 <strong>hello、hello1、hello2</strong> 三条消息</p>
<p>🌭 再启动 <strong>MessageReceiver</strong> 分别消费 <strong>hello、hello2</strong> 两条消息</p>
</blockquote>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20231026160932226.png" alt="image-20231026160932226"></p>
<ul>
<li>在 <strong>RabbitMQ 监控面板</strong>中的显示效果如下：<strong>（2023/10/26午）</strong></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20231026160619142.png" alt="image-20231026160619142"></p>
<h3 id="Work-Queue-多消费者"><a href="#Work-Queue-多消费者" class="headerlink" title="Work Queue  多消费者"></a>Work Queue  多消费者</h3><blockquote>
<p>🍖 推荐阅读：<a target="_blank" rel="noopener" href="https://www.rabbitmq.com/tutorials/tutorial-two-python.html">RabbitMQ tutorial - Work Queues — RabbitMQ</a></p>
</blockquote>
<ul>
<li>生产者 <code>MultiMesProducer</code>：<strong>（2024/01/15午）</strong></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">MultiMesProducer</span> &#123;<br><br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-type">String</span> <span class="hljs-variable">TASK_QUEUE_NAME</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;multi_queue&quot;</span>;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] argv)</span> <span class="hljs-keyword">throws</span> Exception &#123;<br>        <span class="hljs-type">ConnectionFactory</span> <span class="hljs-variable">factory</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">ConnectionFactory</span>();<br>        factory.setHost(<span class="hljs-string">&quot;localhost&quot;</span>);<br><br>        <span class="hljs-keyword">try</span> (<span class="hljs-type">Connection</span> <span class="hljs-variable">connection</span> <span class="hljs-operator">=</span> factory.newConnection();<br>             <span class="hljs-type">Channel</span> <span class="hljs-variable">channel</span> <span class="hljs-operator">=</span> connection.createChannel()) &#123;<br>            <span class="hljs-comment">// 队列持久化</span><br>            channel.queueDeclare(TASK_QUEUE_NAME, <span class="hljs-literal">true</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">null</span>);<br><br>            <span class="hljs-comment">// 发送多条消息</span><br>            <span class="hljs-type">Scanner</span> <span class="hljs-variable">scanner</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Scanner</span>(System.in);<br>            <span class="hljs-keyword">while</span> (scanner.hasNext()) &#123;<br>                <span class="hljs-type">String</span> <span class="hljs-variable">message</span> <span class="hljs-operator">=</span> scanner.next();<br>                <span class="hljs-comment">// 消息持久化</span><br>                channel.basicPublish(<span class="hljs-string">&quot;&quot;</span>, TASK_QUEUE_NAME,<br>                        MessageProperties.PERSISTENT_TEXT_PLAIN,<br>                        message.getBytes(<span class="hljs-string">&quot;UTF-8&quot;</span>));<br>                System.out.println(<span class="hljs-string">&quot; [x] Sent &#x27;&quot;</span> + message + <span class="hljs-string">&quot;&#x27;&quot;</span>);<br>            &#125;<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>消费者 <code>MultiMesReceiver</code>：</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">MultiMesReceiver</span> &#123;<br><br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-type">String</span> <span class="hljs-variable">TASK_QUEUE_NAME</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;multi_queue&quot;</span>;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] argv)</span> <span class="hljs-keyword">throws</span> Exception &#123;<br>        <span class="hljs-type">ConnectionFactory</span> <span class="hljs-variable">factory</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">ConnectionFactory</span>();<br>        factory.setHost(<span class="hljs-string">&quot;localhost&quot;</span>);<br><br>        <span class="hljs-keyword">final</span> <span class="hljs-type">Connection</span> <span class="hljs-variable">connection</span> <span class="hljs-operator">=</span> factory.newConnection();<br><br>        <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">2</span>; i++) &#123;<br>            <span class="hljs-keyword">final</span> <span class="hljs-type">Channel</span> <span class="hljs-variable">channel</span> <span class="hljs-operator">=</span> connection.createChannel();<br>            channel.queueDeclare(TASK_QUEUE_NAME, <span class="hljs-literal">true</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">null</span>);<br>            System.out.println(<span class="hljs-string">&quot; [*] Waiting for messages. To exit press CTRL+C&quot;</span>);<br>            <span class="hljs-comment">// 控制单个消费者的处理任务积压数</span><br>            channel.basicQos(<span class="hljs-number">1</span>);<br><br>            <span class="hljs-type">int</span> <span class="hljs-variable">finalI</span> <span class="hljs-operator">=</span> i;<br>            <span class="hljs-type">DeliverCallback</span> <span class="hljs-variable">deliverCallback</span> <span class="hljs-operator">=</span> (consumerTag, delivery) -&gt; &#123;<br>                <span class="hljs-type">String</span> <span class="hljs-variable">message</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">String</span>(delivery.getBody(), <span class="hljs-string">&quot;UTF-8&quot;</span>);<br><br>                <span class="hljs-keyword">try</span> &#123;<br>                    <span class="hljs-comment">// 处理工作</span><br>                    System.out.println(<span class="hljs-string">&quot; [x] Received &#x27;&quot;</span> + <span class="hljs-string">&quot;编号:&quot;</span> + finalI + <span class="hljs-string">&quot;:&quot;</span> + message + <span class="hljs-string">&quot;&#x27;&quot;</span>);<br>                    <span class="hljs-comment">// channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);</span><br><br>                    Thread.sleep(<span class="hljs-number">2000</span>);<br>                &#125; <span class="hljs-keyword">catch</span> (InterruptedException e) &#123;<br>                    e.printStackTrace();<br>                    channel.basicNack(delivery.getEnvelope().getDeliveryTag(), <span class="hljs-literal">false</span>, <span class="hljs-literal">false</span>);<br>                &#125; <span class="hljs-keyword">finally</span> &#123;<br>                    System.out.println(<span class="hljs-string">&quot; [x] Done&quot;</span>);<br>                    channel.basicAck(delivery.getEnvelope().getDeliveryTag(), <span class="hljs-literal">false</span>);<br>                &#125;<br>            &#125;;<br>            <span class="hljs-comment">// 开启消费监听</span><br>            channel.basicConsume(TASK_QUEUE_NAME, <span class="hljs-literal">false</span>, deliverCallback, consumerTag -&gt; &#123;<br>            &#125;);<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>开启生产者，生产六条消息：</li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240115165134585.png" alt="image-20240115165134585"></p>
<ul>
<li>开启消费者（两个），各每隔两秒消费一条消息：</li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240115165250014.png" alt="image-20240115165250014"></p>
<h3 id="Publish-Subcribe-发布订阅"><a href="#Publish-Subcribe-发布订阅" class="headerlink" title="Publish / Subcribe  发布订阅"></a>Publish / Subcribe  发布订阅</h3><ul>
<li>生产者 <code>FanoutProducer</code>：</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">FanoutProducer</span> &#123;<br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-type">String</span> <span class="hljs-variable">EXCHANGE_NAME</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;fanout-exchange&quot;</span>;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        <span class="hljs-type">ConnectionFactory</span> <span class="hljs-variable">factory</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">ConnectionFactory</span>();<br>        factory.setHost(<span class="hljs-string">&quot;localhost&quot;</span>);<br><br>        <span class="hljs-keyword">try</span> (<span class="hljs-type">Connection</span> <span class="hljs-variable">connection</span> <span class="hljs-operator">=</span> factory.newConnection();<br>             <span class="hljs-type">Channel</span> <span class="hljs-variable">channel</span> <span class="hljs-operator">=</span> connection.createChannel()) &#123;<br>            <span class="hljs-comment">// 创建交换机</span><br>            channel.exchangeDeclare(EXCHANGE_NAME, <span class="hljs-string">&quot;fanout&quot;</span>);<br>            <span class="hljs-type">Scanner</span> <span class="hljs-variable">scanner</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Scanner</span>(System.in);<br>            <span class="hljs-keyword">while</span> (scanner.hasNext()) &#123;<br>                <span class="hljs-type">String</span> <span class="hljs-variable">message</span> <span class="hljs-operator">=</span> scanner.next();<br>                channel.basicPublish(EXCHANGE_NAME, <span class="hljs-string">&quot;&quot;</span>, <span class="hljs-literal">null</span>, message.getBytes(<span class="hljs-string">&quot;UTF-8&quot;</span>));<br>                System.out.println(<span class="hljs-string">&quot; [x] Sent &#x27;&quot;</span> + message + <span class="hljs-string">&quot;&#x27;&quot;</span>);<br>            &#125;<br>        &#125; <span class="hljs-keyword">catch</span> (TimeoutException | IOException e) &#123;<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">RuntimeException</span>(e);<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>消费者 <code>FanoutReceiver</code>：</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">FanoutConsumer</span> &#123;<br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-type">String</span> <span class="hljs-variable">EXCHANGE_NAME</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;fanout-exchange&quot;</span>;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> IOException, TimeoutException &#123;<br>        <span class="hljs-type">ConnectionFactory</span> <span class="hljs-variable">factory</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">ConnectionFactory</span>();<br>        factory.setHost(<span class="hljs-string">&quot;localhost&quot;</span>);<br><br>        <span class="hljs-type">Connection</span> <span class="hljs-variable">connection</span> <span class="hljs-operator">=</span> factory.newConnection();<br>        <span class="hljs-type">Channel</span> <span class="hljs-variable">channel1</span> <span class="hljs-operator">=</span> connection.createChannel();<br>        <span class="hljs-type">Channel</span> <span class="hljs-variable">channel2</span> <span class="hljs-operator">=</span> connection.createChannel();<br>        <span class="hljs-comment">// 声明交换机</span><br>        channel1.exchangeDeclare(EXCHANGE_NAME, <span class="hljs-string">&quot;fanout&quot;</span>);<br>        <span class="hljs-comment">// 创建队列，随机分配一个队列名称</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">queueName1</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;nice_queue&quot;</span>;<br>        channel1.queueDeclare(queueName1, <span class="hljs-literal">true</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">null</span>);<br>        channel2.queueBind(queueName1, EXCHANGE_NAME, <span class="hljs-string">&quot;&quot;</span>);<br><br>        <span class="hljs-type">String</span> <span class="hljs-variable">queueName2</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;fuck_queue&quot;</span>;<br>        channel1.queueDeclare(queueName2, <span class="hljs-literal">true</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">null</span>);<br>        channel2.queueBind(queueName2, EXCHANGE_NAME, <span class="hljs-string">&quot;&quot;</span>);<br><br>        System.out.println(<span class="hljs-string">&quot; [*] Waiting for messages. To exit press CTRL+C&quot;</span>);<br><br>        <span class="hljs-type">DeliverCallback</span> <span class="hljs-variable">deliverCallback1</span> <span class="hljs-operator">=</span> (consumerTag, delivery) -&gt; &#123;<br>            <span class="hljs-type">String</span> <span class="hljs-variable">message</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">String</span>(delivery.getBody(), StandardCharsets.UTF_8);<br>            System.out.println(<span class="hljs-string">&quot; nice &quot;</span> + message + <span class="hljs-string">&quot;&#x27;&quot;</span>);<br>        &#125;;<br><br>        <span class="hljs-type">DeliverCallback</span> <span class="hljs-variable">deliverCallback2</span> <span class="hljs-operator">=</span> (consumerTag, delivery) -&gt; &#123;<br>            <span class="hljs-type">String</span> <span class="hljs-variable">message</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">String</span>(delivery.getBody(), StandardCharsets.UTF_8);<br>            System.out.println(<span class="hljs-string">&quot; fuck &quot;</span> + message + <span class="hljs-string">&quot;&#x27;&quot;</span>);<br>        &#125;;<br><br>        channel1.basicConsume(queueName1, <span class="hljs-literal">true</span>, deliverCallback1, consumer -&gt; &#123;<br>        &#125;);<br>        channel2.basicConsume(queueName2, <span class="hljs-literal">true</span>, deliverCallback2, consumer -&gt; &#123;<br>        &#125;);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>生产者生产消息，所有消费者都能够收到：<strong>（2024/01/15午）</strong></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240115171624222.png" alt="image-20240115171624222"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240115171641966.png" alt="image-20240115171641966"></p>
<h1 id="亮点集锦"><a href="#亮点集锦" class="headerlink" title="亮点集锦"></a>亮点集锦</h1>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97/" class="category-chain-item">消息队列</a>
  
  
    <span>></span>
    
  <a href="/categories/%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97/RabbitMQ/" class="category-chain-item">RabbitMQ</a>
  
  
    <span>></span>
    
  <a href="/categories/%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97/RabbitMQ/%E7%BB%8F%E9%AA%8C/" class="category-chain-item">经验</a>
  
  

  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E7%BB%8F%E9%AA%8C/">#经验</a>
      
        <a href="/tags/RabbitMQ/">#RabbitMQ</a>
      
        <a href="/tags/%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97/">#消息队列</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>驾驭风暴：RabbitMQ实战之旅——揭秘消息队列的无限潜能</div>
      <div>http://example.com/2023/10/25/驾驭风暴：RabbitMQ实战之旅——揭秘消息队列的无限潜能/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Memory</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年10月25日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2024年1月15日</div>
        </div>
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2023/10/27/%E8%81%8C%E4%B8%9A%E7%94%9F%E6%B6%AF%E8%A7%84%E5%88%92/" title="职业生涯规划">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">职业生涯规划</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/10/25/%E6%8E%A2%E7%B4%A2%20Win10%20%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%EF%BC%8C%E8%A7%A3%E9%94%81%E9%9A%90%E8%97%8F%E7%9A%84%E7%A7%98%E5%AF%86%E5%92%8C%E4%B9%90%E8%B6%A3%EF%BC%81/" title="探索Win10操作系统，解锁隐藏的秘密和乐趣！">
                        <span class="hidden-mobile">探索Win10操作系统，解锁隐藏的秘密和乐趣！</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments">
      

    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>Memory | 个人文档站点</span> </a>
<i class="iconfont icon-love"></i> <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>配置指南 | Hexo Fluid 用户手册</span> </a>   
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="leancloud-site-pv-container" style="display: none">
        总访问量 
        <span id="leancloud-site-pv"></span>
         次
      </span>
    
    
      <span id="leancloud-site-uv-container" style="display: none">
        总访客数 
        <span id="leancloud-site-uv"></span>
         人
      </span>
    
    

  
</div>

  
  
    <!-- 备案信息 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      京ICP证123456号
    </a>
  </span>
  
    
      <span>
        <a
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=12345678"
          rel="nofollow noopener"
          class="beian-police"
          target="_blank"
        >
          
            <span style="visibility: hidden; width: 0">|</span>
            <img src="/img/police_beian.png" alt="police-icon"/>
          
          <span>京公网安备12345678号</span>
        </a>
      </span>
    
  
</div>

  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>







  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="/js/leancloud.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
